<%--
  Created by IntelliJ IDEA.
  User: zcah
  Date: 18-5-22
  Time: 上午9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${org.organizationName}</title>
    <style>
        .jiansuo {
            width: 5%;

        }

        .ty {
            padding-left: 10px;
        }

        .bj {
            font-size: 14px;
            align-content: center;
            position: relative;
            top: 8px;
        }
    </style>
</head>

<body>

<div class="modal inmodal" id="wsc-alter-apply" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content flipInY">
            <div class="modal-header" style="padding: 20px 10px;">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">Close</span></button>
                <h5 class="modal-title">用户信息修改</h5>
            </div>
            <div class="modal-body" style="overflow: auto;">
                <div class="form form-horizontal">
                    <form class="user-form">
                        <input type="hidden" class="form-control" id="up_user_id" name="userId">
                        <div class="form-group">
                            <label class="col-xs-3 control-label">姓名</label>
                            <div class="col-xs-9"><input type="text" class="form-control" name="realName" id="up_real_name"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">姓别</label>
                            <div class="col-xs-9"><input type="text" class="form-control" name="playerSex" id="upplayerSex"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">邮箱</label>
                            <div class="col-xs-9"><input type="text" class="form-control" name="email" id="up_email" readonly="readonly"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">证件号码</label>
                            <div class="col-xs-9"><input type="text" class="form-control" id="upidCode" name="idCode"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-3 control-label">手机号</label>
                            <div class="col-xs-9"><input type="text" class="form-control" id="up_phone" name="phone"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">号码簿</label>
                            <div class="col-xs-9"><input type="text" class="form-control" id="upplayerNum" name="playerNum">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary wsc-save-apply-btn">保存</button>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">

        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="table-responsive">
                    <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                        <div id="wsc-search">
                            <form action="" onsubmit="return false;" id="form1">
                                <div class="col-sm-3 ty" style="width: auto;">
                                    <input type="text" name=phone" placeholder="手机号" class="form-control">
                                </div>
                                <div class="col-sm-3 ty" style="width: auto;">
                                    <input type="text" name="email" placeholder="邮箱" class="form-control">
                                </div>
                                <div class="col-sm-3 ty" style="width: auto;">
                                    性别&nbsp;&nbsp;
                                    <select name="playerSex" class="form-control inline">
                                        <option value="">全部</option>
                                        <option value="男">男</option>
                                        <option value="女">女</option>
                                    </select>
                                </div>
                                <div class="col-sm-3 m-b-xs ty" style="width: auto;">
                                    号码簿&nbsp;&nbsp;
                                    <select name="havePlayerNum" class="form-control inline">
                                        <option value="">全部</option>
                                        <option value="0">未分配</option>
                                        <option value="1">已分配</option>
                                    </select>
                                </div>
                                <div class="col-sm-3 jiansuo ty">
                                    <button type="button" id="wsc-search-btn" class="btn btn-sm btn-primary"> 检索</button>

                                </div>
                            </form>
                        </div>
                    <table class="table table-striped table-bordered table-hover dataTables-mls">
                        <tbody>
                        </tbody>
                    </table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

</body>
<div id="scripts">

    <!-- scripts -->
    <script type="text/javascript">
        $(document).ready(function () {
            var wsc_table = $('.dataTables-mls').DataTable({
                "dom": '<"wsc-search"><"html5buttons"B>Tfgtlpi',
                "aLengthMenu": [10, 25, 50, 100, 1000],
                buttons: [],
                "language": {url: '${ctx}/locales/datatable.json', 'zeroRecords': '没有参赛者的记录'},
                searching: false,
                "searchDelay": 2000,
                "ajax": {
                    "url": "/findAllUser",
                    data: {
                        //matchId: matchId
                    }
                },
                "columns": [
                    {"data": "phone", "title": "手机号", "orderable": false, "searchable": false},
                    {"data": "email", "title": "邮箱", "orderable": false, "searchable": false},
                    {"data": "createAt", "title": "创建时间", "orderable": false, "searchable": false},
                    {"data": "realName", "title": "姓名", "orderable": false, "searchable": false},
                    {"data": "updateAt", "title": "更新时间", "orderable": false, "searchable": false},
                    {"data": "phone", "title": "证件类型", "orderable": false, "searchable": false},
                    {"data": "phone", "title": "证件号码", "orderable": false, "searchable": false}
                ],
                "columnDefs": [
                    {
                        "targets": 7,
                        "searchable": false,
                        "title": "操作",
                        render: function (data, type, row, meta) {
                            var _info = '<a href="javascript:void(0)" class="up-person" data-user-id="' + row.userId + '">编辑</a >';
                            return _info;
                        }
                    }
                ],
                "serverSide": true
            });


            $('.dataTables-mls').on('init.dt', function () {
                $("div.wsc-search").html($('#wsc-search').html());
                $('#wsc-search').remove();
                $('.wsc-date-yymmdd-ch').datetimepicker({
                        format: 'yyyy-mm-dd hh:ii:ss',
                        todayBtn: "linked",//选中今天
                        keyboardNavigation: false,//不通过方向键改变日期
                        forceParse: false,//不强制解析输入框中的值
                        language: 'zh-CN',
                        autoclose: true//选择日期后自动关闭
                    }
                );
                $('#wsc-search-btn').bind('click', function () {

                    wsc_table.ajax.url("/findAllUser?" + $('.wsc-search > #form1').serialize()).load();
                });
                $('#wsc-clear-btn').bind('click', function () {
                });

            });


            $(".wsc-save-apply-btn").on('click',function () {
                $('.error_info').remove();
                var flg_sub = true;
                var $_input_obj = $(".form-group").find('input');
                $.each($_input_obj,function () {
                    if(!$(this).val()){
                        $(this).after("<span class='error_info'>&nbsp;&nbsp;该项不能为空</span>");
                        flag_sub =false;
                    }
                });
                if(!flg_sub){
                    return;
                }
                var _apply_obj =  $(".user-form").serialize();

                $.ajax({
                    type: "post",
                    url: "/upUser",
                    data: _apply_obj,
                    dataType: "json",
                    success: function (data) {
                        if(data.msg == ""){
                            swal("修改成功", "", "warning");
                            self.location.reload();
                        }else{
                            swal(data.msg,"", "warning");
                        }
                    }
                });
            })

        });


        $(".dataTables-mls").on('click', '.up-person', function () {
            var _user_id = $(this).attr('data-user-id');
            if(!_user_id){
                swal("用户不存在", "", "warning");
                return;
            }
            $.ajax({
                type: 'get',
                url: '${ctx}/findUserByUserId',
                data: {
                    userId: _user_id
                },
                dataType: 'json',
                success: function (data) {
                    if(data.result.dataDict){
                        var _user = data.result.dataDict;
                        $('#up_user_id').val(_user_id);
                        $('#up_real_name').val(_user.realName);
                        $('#up_phone').val(_user.phone);
                        $('#up_email').val(_user.email);
                        $('#wsc-alter-apply').modal('show');
                    }else{
                        swal(data.msg, "用户不存在", "warning");
                    }
                }
            });
        })

    </script>

</div>
</html>
